package com.itboye.sunsun.adapter;

import java.util.List;

import com.itboye.sunsun.R;
import com.itboye.sunsun.Application.App;
import com.itboye.sunsun.beans.MyCollectBean;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class CollectGoodsAdapter extends BaseAdapter{
	
	private Context context;
	private List<MyCollectBean> list;
	public CollectGoodsAdapter(Context context,List<MyCollectBean> list)
	{
		this.context=context;
		this.list=list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	final class ViewHolder
	{
		TextView textview;
		ImageView imagestate;
	}
	
	
	@SuppressLint("NewApi")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder viewHolder=null;
		if(convertView==null)
		{
			convertView=LayoutInflater.from(context).inflate(R.layout.mycollect_listview_item, null);
			
			viewHolder=new ViewHolder();
			viewHolder.imagestate=(ImageView) convertView.findViewById(R.id.stateimagein);
			convertView.setTag(viewHolder);
		}else
		{
			viewHolder=(ViewHolder) convertView.getTag();
		}
		
		

		if (list.get(position).isSelected()) {
			viewHolder.imagestate.setBackground(App.ctx.getResources().getDrawable(
					R.drawable.select));
		} else {
			viewHolder.imagestate.setBackground(App.ctx.getResources().getDrawable(
					R.drawable.un_select));

		}
		
		
	//	Toast.makeText(App.ctx, list.get(position).isSelected()+"", 0).show();
		
		
		
		return convertView;
	}

}
